package vn.conghuy.talkwithme.responsor.action;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.provider.MediaStore;

public class OpenAppAction extends Action {

	public OpenAppAction(Context context) {
		super(context);
	}
	
	void launchCalendar(){
		Intent calendarIntent = new Intent() ;
		calendarIntent.setClassName("com.android.calendar","com.android.calendar.LaunchActivity");
		context.startActivity(calendarIntent);
	}
	
	boolean launchFacebook(){
		return launchPackage("com.facebook.katana");
	}
	
	boolean launchYahoo(){
		return launchPackage("com.yahoo.mobile.client.android.im");
	}
	
	public boolean launchIntent(String type){
		if(type.equals("[BROWSER]")){
			Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"));
			context.startActivity(i);
			return true;
		}
		else if(type.equals("[MUSIC]")){
			Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
			context.startActivity(intent);
			return true;
		}
		return false;
	}
	public boolean launchPackage(String packageName){
		try{
			Intent i = new Intent(Intent.ACTION_MAIN);
			PackageManager manager = context.getPackageManager();
			i = manager.getLaunchIntentForPackage(packageName);
			if(i!= null){
				i.addCategory(Intent.CATEGORY_LAUNCHER);
				context.startActivity(i);
				return true;
			}
		}
		catch(ActivityNotFoundException ex){
		}
		return false;
	}

}
